<template>
  <div class="JobInfo-container">
    <title-name title="岗位信息"></title-name>
    <div class="table-operateors mb20">
      <!-- <a-button type="primary">历史岗位信息</a-button> -->
      <a-button
        type="primary"
        v-if="pageType !== 'look' && !$route.meta.isPim"
        @click="visibleState.bindJob = true"
      >绑定岗位</a-button>
    </div>
    <s-table
      ref="table"
      size="default"
      rowKey="id"
      :columns="columns"
      :data="loadData"
      :alert="true"
      show-size-changer
      show-quick-jumper
      :showPagination="false"
      :scroll="{ y: 450 }"
    >
      <template
        slot="sort"
        slot-scope="text, record, index"
      >
        <span>{{ index + 1 }}</span>
      </template>
      <template
        slot="isMainPost"
        slot-scope="text"
      >
        <span>{{ text === 1 ? '是' : '否' }}</span>
      </template>
      <template
        slot="isLeader"
        slot-scope="text"
      >
        <span>{{ text ? '是' : '否' }}</span>
      </template>
    </s-table>
    <modalBindOrg
      :form="commonData"
      :visibleJob="visibleState.bindJob"
      @handleCancel="visibleState.bindJob = false"
      @confirm="handleBindConfirm"
    />
  </div>
</template>

<script>
import { getPostPNameByUser } from '@/api/commons.js'
import modalBindOrg from '@/views/systemManage/userManage/modalBindOrg.vue'
import { STable } from '@/components'
const columns = [
  {
    title: '序号',
    dataIndex: 'sort',
    width: '65px',
    scopedSlots: { customRender: 'sort' }
  },
  {
    title: '岗位名称',
    dataIndex: 'name'
  },
  {
    title: '组织关系',
    dataIndex: 'pname'
  },
  {
    title: '岗位编号',
    dataIndex: 'code'
  },
  {
    title: '是否为主岗位',
    dataIndex: 'isMainPost',
    scopedSlots: { customRender: 'isMainPost' }
  },
  {
    title: '是否为领导',
    width: '150px',
    dataIndex: 'isLeader',
    scopedSlots: { customRender: 'isLeader' }
  }
]
export default {
  name: 'JobInfo',
  components: {
    STable,
    modalBindOrg
  },
  props: {
    pageType: {
      type: String,
      default: 'add'
    },
    employeeId: {
      type: String,
      default: ''
    },
    userId: {
      type: String,
      default: ''
    },
    commonData: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      columns,
      queryParam: {},
      visibleState: {
        bindJob: false
      }
    }
  },
  methods: {
    handleBindConfirm(data) {
      this.visibleState.bindJob = false
      this.$nextTick(() => {
        this.$refs.table.refresh(true)
      })
    },
    async loadData(parameter) {
      const params = {
        userId: this.userId
      }
      const requestParameters = Object.assign({}, parameter, this.queryParam, params)
      return getPostPNameByUser(requestParameters)
    }
  }
}
</script>

<style>
</style>